module Holo
  class Installer
    attr_accessor :pod_file, :customization_hash, :holo_files

    def self.install(pod_file, options = {})
      inst = Installer.new
      inst.pod_file = pod_file
      inst.read_customization_yml
      inst.read_holo_files
      inst.pod_call
      inst
    end

    def read_customization_yml
      yml_path = File.expand_path('.customization.yml', Dir.pwd)
      @customization_hash = if !File.exist?(yml_path)
                              {}
                            else
                              YAML.safe_load(File.read(yml_path))
                            end
      @customization_hash ||= {}
      @customization_hash
    end

    def read_holo_files
      @holo_files = Dir.glob(File.expand_path("holo_files/**/*.rb", Dir.pwd))
    end

    def pod_call
      @holo_files.map do |f|
        pod = HoloFile.from_file(f)
        pod.customized = @customization_hash[pod.name]
        pod.pod_by(@pod_file)
      end
    end
  end
end
